/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.babble.blog.controller;

import com.babble.blog.entity.Blog;
import com.babble.blog.service.IBlogService;
import com.babble.blog.vo.BlogSaveVO;
import com.babble.blog.vo.BlogUpdVO;
import com.babble.blog.vo.BlogVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springblade.common.exception.MsgException;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 博客文章表 控制器
 *
 * @author Blade
 * @since 2021-11-19
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/blog")
@Api(value = "博客文章表", tags = "博客文章表接口")
public class BlogController  {
	private final IBlogService blogService;
	@ApiOperation(value = "发布博客")
	@PostMapping("save")
	public R save(@Valid BlogSaveVO blogSaveVO) throws MsgException, MsgException, MsgException {
		blogService.saveBlog(blogSaveVO);
		return R.data("上传");
	}

	/**
	 *
	 * num 页数
	 * size 往后哪几个
	 * id 分类ID 可以为空
	 * type blog_category_id:根据分类 or tag_id:根据标签 可以为空 or id 根据ID
	 * serarchType 按照日期create_time,点击数:click_count,收藏数:collect_count
	 * sort 0正序 1 倒叙
	 * @return
	 */
//	@ApiOperation(value = "根据分类或者标签分页查找文章",notes = "博客文章列表")
//	@GetMapping("list")
//	public R<List<BlogVO>> listOfBlogCategory(QueryBlogDTO queryBlogDTO){
//		List<BlogVO> blogs = blogService.list(queryBlogDTO);
//		return R.data(blogs);
//	}
	@ApiOperation(value = "博客添加点击量")
	@GetMapping("clickBlog")
	public R<List<Blog>> clickBlog(@RequestParam("id")String id) throws MsgException {
		blogService.clickBlog(id);
		return R.success("点击成功");
	}
	@ApiOperation(value = "根据ID找文章",notes = "ID")
	@GetMapping("listById")
	public R<List<BlogVO>> listOfBlogCategory(@RequestParam("id")String id) throws MsgException {
		List<BlogVO> blogs = blogService.listById(id);
		return R.data(blogs);
	}
	@ApiOperation(value = "修改博客")
	@PostMapping("upd")
	public R upd(@Valid BlogUpdVO blogUpdVO) throws MsgException, MsgException, MsgException {
		blogService.updBlog(blogUpdVO);
		return R.data("修改成功");
	}
	@ApiOperation(value = "删除博客")
	@PostMapping("del")
	public R del(@RequestParam("id")String id) throws MsgException, MsgException, MsgException {
		blogService.del(id);
		return R.data("删除成功");
	}
}
